<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="地图名称" prop="dataname">
        <el-input
          v-model="queryParams.dataname"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="责任人" prop="firstpeople">
        <el-input
          v-model="queryParams.firstpeople"
          placeholder="请输入第一责任人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存放位置" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入存放位置"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地图分类" prop="category">
        <el-input
          v-model="queryParams.category"
          placeholder="请输入分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="二级分类" prop="secondclassify">
        <el-input
          v-model="queryParams.secondclassify"
          placeholder="请输入二级分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地图条码" prop="barcode">
        <el-input
          v-model="queryParams.barcode"
          placeholder="请输入条码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建日期" prop="daydate">
<!--        <el-input
          v-model="queryParams.daydate"
          placeholder="请输入日期"
          clearable
          @keyup.enter.native="handleQuery"
          style="width:150px"
        />-->
        <el-date-picker
          v-model="queryParams.daydate"
          type="date"
          placeholder="请输入日期"
          style="width:92%"
          clearable
          value-format="yyyy-MM-dd"
          @change="getFilterData"

        />
        <!--
          @keyup.enter.native="handleQuery"-->
      </el-form-item>
    <!--  <el-form-item label="附件" prop="enclosure">
        <el-input
          v-model="queryParams.enclosure"
          placeholder="请输入附件"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门ID" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新者" prop="updateBy">
        <el-input
          v-model="queryParams.updateBy"
          placeholder="请输入更新者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:map:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:map:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:map:remove']"
        >删除</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['system:map:import']"
        >导入
        </el-button>
      </el-col>


      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:map:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mapList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" :index="indexMethond" />
      <el-table-column label="名称" align="center" prop="dataname" />
      <el-table-column label="责任人" align="center" prop="firstpeople" />
      <el-table-column label="存放位置" align="center" prop="position" />
      <el-table-column label="分类" align="center" prop="category" />
      <el-table-column label="二级分类" align="center" prop="secondclassify" />
      <el-table-column label="条码" align="center" prop="barcode" />
    <!--  <el-table-column label="日期" align="center" prop="daydate" />-->
   <!--   <el-table-column label="状态" align="center" prop="status" />-->
     <!-- <el-table-column label="附件" align="center" prop="enclosure" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="部门ID" align="center" prop="deptId" />
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新者" align="center" prop="updateBy" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="备注" align="center" prop="remark" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160" fixed="right">
        <template slot-scope="scope">
        <!--  <el-button
            size="mini"
            type="text"
            icon="el-icon-s-check"
            @click="handleBorrow(scope.row)"
            v-hasPermi="['system:map:edit']"
          >借阅</el-button>-->
          <el-button
            size="mini"
            type="text"

            @click="handleUpdate(scope.row)"

          >修改</el-button>
          <el-button
            size="mini"
            type="text"

            @click="handleDelete(scope.row)"

          >删除</el-button>
          <el-button
            size="mini"
            type="text"

            @click="handlelook(scope.row)"

          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改地图信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-container >
          <el-header height="40px">
            <el-divider content-position="left">
              <p style="color: #00afff;font-size: 18px;">地图信息</p>
            </el-divider>
          </el-header>
          <el-main >
            <el-table-row>
              <el-col span="8">
                <el-form-item label="地图名称" prop="dataname">
                  <el-input v-model="form.dataname" placeholder="请输入名称" />
                </el-form-item>
              </el-col>
              <el-col span="8">
                <el-form-item label="责任人" prop="firstpeople">
                  <el-input v-model="form.firstpeople" placeholder="请输入第一责任人" />
                </el-form-item>
              </el-col>
              <el-col span="8">
                <el-form-item label="存放位置" prop="position">
                  <el-input v-model="form.position" placeholder="请输入存放位置" />
                </el-form-item>
              </el-col>
            </el-table-row>
            <!--            <el-table-row>


                        </el-table-row>-->
            <el-table-row>
              <el-col span="8">
                <el-form-item label="地图分类" prop="category">
                  <el-input v-model="form.category"  placeholder="请输入分类" />
                </el-form-item>
              </el-col>
              <el-col span="8">
                <el-form-item label="二级分类" prop="secondclassify">
                  <el-input v-model="form.secondclassify" placeholder="请输入二级分类" />
                </el-form-item>
              </el-col>
              <el-col span="8">
                <el-form-item label="地图条码" prop="barcode">
                  <el-input v-model="form.barcode" placeholder="请输入条码" />
                </el-form-item>
              </el-col>
            </el-table-row>
          </el-main>
          <el-header height="40px">
            <el-divider content-position="left">
              <p style="color: #00afff;font-size: 18px;">附件信息</p>
            </el-divider>
          </el-header>
          <el-main>
            <el-table-row>
              <el-col span="24">
                <el-form-item label="电子附件" prop="enclosure">
                  <file-upload   v-model="form.enclosure"/>
                </el-form-item>
              </el-col>
            </el-table-row>
          </el-main>
          <el-header height="40px">
            <el-divider content-position="left">
              <p style="color: #00afff;font-size: 18px;">备注信息</p>
            </el-divider>
          </el-header>
          <el-main >
            <el-table-row>
              <el-col span="24">
                <el-form-item label="备注信息" prop="remark">
                  <el-input :rows="1" v-model="form.remark" type="textarea" placeholder="请输入内容" />
                </el-form-item>
              </el-col>
            </el-table-row>
          </el-main>
        </el-container>
      <!--  <el-form-item label="日期" prop="daydate">
          <el-input v-model="form.daydate" placeholder="请输入日期" />
        </el-form-item>-->

         <!-- <el-form-item label="附件" prop="enclosure">
            <file-upload v-model="form.enclosure"/>
          </el-form-item>-->

     <!--   <el-form-item label="附件" prop="enclosure">
          <el-input v-model="form.enclosure" placeholder="请输入附件" />
        </el-form-item>
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门ID" />
        </el-form-item>-->

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>



    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px">
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 借阅地图信息对话框 -->
    <el-dialog :title="borrow.title" :visible.sync="borrow.open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名称" prop="dataname">
          <el-input v-model="form.dataname" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="责任人" prop="firstpeople">
          <el-input v-model="form.firstpeople" placeholder="请输入第一责任人" />
        </el-form-item>
        <el-form-item label="存放位置" prop="position">
          <el-input v-model="form.position" placeholder="请输入存放位置" />
        </el-form-item>
        <el-form-item label="分类" prop="category">
          <el-input v-model="form.category" placeholder="请输入分类" />
        </el-form-item>
        <el-form-item label="二级分类" prop="secondclassify">
          <el-input  v-model="form.secondclassify" placeholder="请输入二级分类" />
        </el-form-item>
        <el-form-item label="条码" prop="barcode">
          <el-input v-model="form.barcode" placeholder="请输入条码" />
        </el-form-item>
        <el-form-item label="日期" prop="daydate">
          <el-input v-model="form.daydate" placeholder="请输入日期" />
        </el-form-item>
        <!--   <el-form-item label="附件" prop="enclosure">
             <el-input v-model="form.enclosure" placeholder="请输入附件" />
           </el-form-item>
           <el-form-item label="用户ID" prop="userId">
             <el-input v-model="form.userId" placeholder="请输入用户ID" />
           </el-form-item>
           <el-form-item label="部门ID" prop="deptId">
             <el-input v-model="form.deptId" placeholder="请输入部门ID" />
           </el-form-item>-->
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="borrowsubmitForm">确 定</el-button>
        <el-button @click="borrowcancel">取 消</el-button>
      </div>
    </el-dialog>













  </div>
</template>
<style >
.el-form-item{
  margin-bottom: 18px;
}
.el-dialog__footer{
  padding-bottom: 10px;
}

.el-dialog__body{
  padding-top: 0px;
  padding-bottom: 0px;
}
.el-header, .el-footer {
  background-color: #FFFFFF;
  color: #333;
  text-align: left;
  line-height: 20px;
  font-style: oblique;

}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  text-align: center;
  line-height: 160px;
}

.el-main {
  background-color: #FFFFFF;
  color: #333;
  text-align: center;
  line-height: 120px;
}

body > .el-container {
  margin-bottom: 0px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

/*对话框标题样式*/
.el-dialog__title{
  /*color: #1ab394;*/
  font-weight: bold;
  font-size: 20px;
}
</style>
<script>
import { listMap, getMap, delMap, addMap, updateMap } from "@/api/group/whd/map";
import { getToken } from "@/utils/auth";
export default {
  name: "Map",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 地图信息表格数据
      mapList: [],
      // 弹出层标题
      title: "",
      // 借阅弹窗
      borrow:{
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: "",
      },
      // 是否显示弹出层
      open: false,
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/map/importData"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dataname: null,
        firstpeople: null,
        position: null,
        category: null,
        secondclassify: null,
        barcode: null,
        daydate: null,
        status: null,
        enclosure: null,
        userId: null,
        deptId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    const mapname = this.$route.query.mapname;
    const firstname = this.$route.query.firstname;
    const maplocal = this.$route.query.maplocal;
    const barcode = this.$route.query.barcode;

    console.log(mapname+"mapname");
    console.log(firstname+"firstname");
    if (mapname) {
      // 获取表详细信息
      this.queryParams.dataname=mapname;
      this.queryParams.barcode=barcode;
      listMap(this.queryParams).then(response => {
        this.mapList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    }else if(firstname){
      // 获取表详细信息
      this.queryParams.firstpeople=firstname;
      this.queryParams.barcode=barcode;
      listMap(this.queryParams).then(response => {
        this.mapList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    }else if(maplocal){
      // 获取表详细信息
      this.queryParams.position=maplocal;
      this.queryParams.barcode=barcode;
      listMap(this.queryParams).then(response => {
        this.mapList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    }else if(barcode){
      // 获取表详细信息

      this.queryParams.barcode=barcode;
      listMap(this.queryParams).then(response => {
        this.mapList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    }
    else{
      this.getList();
    }

  },
  methods: {
indexMethod(){
  return index+1;
},
    getFilterData() {
      this.$emit('getFilterData', this.form.daydate)
    },
    /** 借阅按钮操作 */
    handleBorrow(row) {
      this.reset();
      const id = row.id || this.ids
    /*  getVerify(id).then(response => {
        this.form = response.data;
        this.xiang.open = true;
        this.xiang.title = "文件详情";
      });*/
      this.borrow.open = true;
      this.borrow.title = "借阅信息";
    },
    // 取消按钮
    borrowcancel() {
      this.borrow.open = false;
      this.reset();
    },
    /** 借阅提交按钮 */
    borrowsubmitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          fileUpdate(this.form).then(response => {
            this.$modal.msgSuccess("上传成功");
            this.fileadd.open = false;
            this.getList();

          });
        }
      });

    },

    /** 查询地图信息列表 */
    getList() {
      this.loading = true;
      listMap(this.queryParams).then(response => {
        this.mapList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dataname: null,
        firstpeople: null,
        position: null,
        category: null,
        secondclassify: null,
        barcode: null,
        daydate: null,
        status: "0",
        enclosure: null,
        userId: null,
        deptId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getMap(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMap(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMap(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除地图信息数据？').then(function() {
        return delMap(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('/system/map/importTemplate', {}, `地图信息导入表.xlsx`)
    },

    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "导入";
      this.upload.open = true;
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", {dangerouslyUseHTMLString: true});
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },


    /** 详情操作 */
    handlelook(row) {
      const id = row.id;
      // const tableName = row.tableName || this.tableNames[0];
      const params = {pageNum: this.queryParams.pageNum};

      this.$router.push({path: "/basedata/mapdetail", query: {id}});
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('system/map/export', {
        ...this.queryParams
      }, `地图信息导出表.xlsx`)
    }
  }
};
</script>
